Skip to content

fix(ghostty): keep the first font-family when importing config - #16090

Closed
maxmilian wants to merge 3 commits into
stablyai:mainfrom
maxmilian:fix/ghostty-import-font-family-order
Closed

maxmilian wants to merge 3 commits into
stablyai:mainfrom
maxmilian:fix/ghostty-import-font-family-order

Conversation

@maxmilian

@maxmilian maxmilian commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Ghostty lets you list font-family more than once — the first one is the font you want, the rest are backups for characters the first one doesn't have. When importing that config, Orca kept the last one instead of the first, so you ended up with your backup font as your main font.

What Changed

One handler in src/main/ghostty/mapper.ts. The font-family handler now reads the unflattened value and takes the first non-empty entry, instead of receiving the already-flattened "last occurrence" string.

Two test cases added to the existing src/main/ghostty/mapper.test.ts.

Why

The parser was never the problem — parseGhosttyConfig already preserves repeated keys correctly as a string[]. The value is lost one layer up, in the mapper's generic flattening:

const value = Array.isArray(rawValue) ? (rawValue.at(-1) ?? '') : rawValue

That default is right for most Ghostty keys, where a later line genuinely overrides an earlier one. font-family is one of the repeatable keys where it isn't: the first entry is the primary face and the rest are the fallback chain, so .at(-1) picks the least-preferred face.

Why this approach: handlers already receive the unflattened value as their second argument (parser(value, rawValue)), and palette already uses exactly that to read all of its own repeats. So this needs no new mechanism and no change to the shared flattening — it reuses the escape hatch the mapper already has, and leaves every other key's behavior untouched.

Scope, deliberately narrow: this only changes which single face is imported. Turning terminalFontFamily into a real fallback stack is #8428's territory, and I did not want to collide with it. This change should merge cleanly either way.

Linked Issue

Fixes #15985

Visual Proof

N/A — there is no UI or interaction change. This is a pure config-parsing fix in the main process; the only observable difference is which font name lands in terminalFontFamily after importing a Ghostty config. That difference is asserted directly in the tests below rather than shown as pixels.

Testing

Red-first, against the exact case in the issue. Added to src/main/ghostty/mapper.test.ts:

  • keeps the first font-family when the key is repeated — ['Menlo', 'Monaco'] must import as Menlo
  • skips blank entries when picking the first font-family — [' ', 'Fira Code', 'Monaco'] must import as Fira Code

Both fail on main before the change (expected 'Monaco' to be 'Menlo' / expected 'Monaco' to be 'Fira Code') and pass after. Full ghostty suite: 7 files, 151 tests passed.

Local gates, all on node 24.19.0 / pnpm 10.24.0:

gate result
pnpm typecheck pass
pnpm lint pass
pnpm test 6110 files / 57485 tests passed — see note below
pnpm build pass

One pre-existing failure in the full run, not from this change: src/relay/git-handler-fork-remote-exec.test.ts > adds and removes the fork remote expects https://github.com/... but gets git@github.com:.... I verified it by stashing this diff and re-running on a clean tree — it fails identically there. It's my local git insteadOf config rewriting HTTPS remotes to SSH, not something this PR touches.

Platform tested: macOS (Apple Silicon). See Notes on why the other platforms don't need separate coverage here.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude Code (Claude Opus 5). I traced the root cause, chose the approach, and verified every claim above myself — the red-before/green-after runs and the clean-tree control run for the pre-existing failure were all executed locally, not assumed.

Review

AI code review summary, per CONTRIBUTING:

  • Cross-platform (Linux / Windows / macOS): no platform-conditional code, no path handling, no shell invocation. The change is string selection inside an already-parsed config object, so behavior is identical on all three. Ghostty itself is macOS/Linux, but the importer is platform-agnostic and this doesn't change that.
  • SSH / remote / local: the Ghostty importer runs in the main process against a local config file. No relay, no remote worktree, no wire protocol involved — this code path doesn't differ between local and SSH sessions.
  • Supported agents / integrations: none touched. terminalFontFamily is a terminal appearance setting; no agent, MCP, or integration surface reads or writes it here.
  • Performance: .find() over the entries of one config key, bounded by how many times a user wrote font-family in their config (realistically ≤ 5). Strictly cheaper than the .at(-1) path it bypasses in no meaningful way, and it runs once per import, not per frame or per keystroke.
  • UI quality: no UI change. The user-visible effect is that the imported font is now the one they configured as primary.
  • Security: no new input surface. The value already flowed from the same file into the same setting; only which element of an existing array is selected has changed. No injection, no path, no exec.
  • Backwards compatibility: users who already imported a multi-font-family config keep their current setting until they re-import — this changes import behavior, not stored settings, so nothing is silently rewritten under them. Single-font-family configs (the overwhelming majority) are completely unaffected: the non-array branch is unchanged.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Covered in Review above: no security surface, no platform-conditional code, no SSH/remote path, no mobile surface, no agent/integration contract, negligible performance cost, and import-only behavior change with no silent rewrite of existing settings.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Ghostty treats a repeated `font-family` as a fallback chain: the first entry
is the primary face and the rest are fallbacks. The mapper flattens repeated
keys with `rawValue.at(-1)`, which is the right default for keys where a later
line overrides an earlier one, but for font-family it imported the
least-preferred face — `Menlo` then `Monaco` arrived as `Monaco`.

The parser was already correct; it preserves repeats as a string[]. Read that
unflattened value in the font-family handler and take the first usable entry,
the same way `palette` already reads its own repeats via the second handler
argument.

Scope: this only changes which single face is imported. Turning
terminalFontFamily into a fallback stack is stablyai#8428's territory.

Fixes stablyai#15985
@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fa2abbf-16b7-420b-be05-e9501966f0ec

📥 Commits

Reviewing files that changed from the base of the PR and between d95e13d and b74498c.

📒 Files selected for processing (2)
  • src/main/ghostty/mapper.test.ts
  • src/main/ghostty/mapper.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/ghostty/mapper.ts
  • src/main/ghostty/mapper.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Updated font-family parsing to handle scalar and repeated values. Empty repeated entries now reset the list. The mapper selects the first non-empty value after the last reset. Added a test for Fira Code, empty, Monaco, which maps to terminalFontFamily: 'Monaco'.

Merge Risk: ⚪ Minimal · up to b7449

This localized import fix selects the first non-empty font-family entry while leaving other configuration behavior unchanged. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: importing the first repeated Ghostty font-family entry instead of the last.
Description check ✅ Passed The description follows the repository template and explains the behavior, rationale, linked issue, testing, scope, AI disclosure, and checklist status. It correctly marks visual proof as not applicab…
Linked Issues check ✅ Passed The changes satisfy issue #15985 by selecting the first applicable repeated font-family entry, handling reset entries, preserving shared flattening behavior, and adding regression tests.
Out of Scope Changes check ✅ Passed The changes are limited to the Ghostty font-family mapper and its tests. Reset handling and blank-entry behavior are directly related to selecting the applicable primary font.
Full details: Description check

Explanation

The description follows the repository template and explains the behavior, rationale, linked issue, testing, scope, AI disclosure, and checklist status. It correctly marks visual proof as not applicable.

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e8f0f44e-ed84-4a60-9494-0991b0e09165

📥 Commits

Reviewing files that changed from the base of the PR and between c3a1694 and a637222.

📒 Files selected for processing (2)
  • src/main/ghostty/mapper.test.ts
  • src/main/ghostty/mapper.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +219 to +224
'font-family': (v, rawValue) => {
const first = Array.isArray(rawValue) ? rawValue.find((entry) => entry.trim().length > 0) : v
if (typeof first !== 'string' || first.trim().length === 0) {
return null
}
return { key: 'terminalFontFamily', value: v }
return { key: 'terminalFontFamily', value: first }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Allow trailing blank entries to reach the font-family parser.

When rawValue is ['Fira Code', ' '], the loop uses the last entry as value. Line 295 then marks the key unsupported before this parser runs. The valid primary font is lost. Skip the generic blank check for font-family; this parser already returns null when all entries are blank. Add a regression test for a trailing blank entry.

Proposed fix
-    if (!value.trim()) {
+    if (key !== 'font-family' && !value.trim()) {
       unsupportedKeys.push(key)
       continue
     }

…ing value

Ghostty documents an empty value on a repeatable key as resetting the list, so a
config ending in `font-family = ` has cleared its fonts deliberately. Importing
the earlier entry would resurrect a font the user removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR corrects Ghostty font-family import behavior while preserving reset semantics.

  • Selects the first active font in a repeated fallback chain.
  • Discards entries before the final empty reset.
  • Adds coverage for repeated fonts, blank entries, mid-list resets, and trailing resets.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/main/ghostty/mapper.ts The mapper now selects the first nonblank font after the final reset, fully addressing the previously reported reset-boundary issue.
src/main/ghostty/mapper.test.ts Tests cover ordinary fallback chains and the leading, middle, and trailing blank-entry cases relevant to reset behavior.

Reviews (2): Last reviewed commit: "fix(ghostty): honor the font-family rese..." | Re-trigger Greptile

Comment thread src/main/ghostty/mapper.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 53fea7eb-12b4-41f6-9709-a2f038f48117

📥 Commits

Reviewing files that changed from the base of the PR and between a637222 and d95e13d.

📒 Files selected for processing (1)
  • src/main/ghostty/mapper.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment thread src/main/ghostty/mapper.test.ts Resolved
…rimary face

An empty entry in a repeated font-family resets the list, so only the entries
after the last reset are still in effect. Searching the whole array imported a
face the config had explicitly cleared -- `['Fira Code', '', 'Monaco']` yielded
Fira Code instead of Monaco.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@nwparker

nwparker commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Thank you @maxmilian for tracking this down! The fix landed in #37292 (same first-entry-after-reset approach, plus fallback reporting and cross-file lists), so I'm closing this in favor of it.

@nwparker nwparker closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ghostty import keeps the last font-family instead of the first

2 participants